package it.lovaex.scb.unittests;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;
import java.util.Date;

import it.lovaex.scb.factory.GroceryFactory;
import it.lovaex.scb.model.GroceryItem;

import org.junit.Assert;
import org.junit.Test;

public class GroceryFactoryTest {
	
	private String groceryItemName = "name";
	private Date expirationDate = new Date();
	private BigDecimal price = new BigDecimal(100);
	
	@Test
	public void test_factory_create_grocery_item() {
		GroceryItem result = GroceryFactory.create(groceryItemName, price);
		GroceryItem expected = new GroceryItem(groceryItemName, price, expirationDate);
		assertEquals(result.expirationDate(), expected.expirationDate());
		assertEquals(result.getDescription(), expected.getDescription());
		assertEquals(result.getName(), expected.getName());
		assertEquals(result.getPrice(), expected.getPrice());
	}
	
	@Test
	public void test_factory_create_grocery_item_with_expiration_date() {
		GroceryItem result = GroceryFactory.create(groceryItemName, price, expirationDate);
		GroceryItem expected = new GroceryItem(groceryItemName, price, expirationDate);
		assertEquals(result.expirationDate(), expected.expirationDate());
		assertEquals(result.getDescription(), expected.getDescription());
		assertEquals(result.getName(), expected.getName());
		assertEquals(result.getPrice(), expected.getPrice());
	}
	
	@Test
	public void test_create_new_item_every_times(){
		GroceryItem first = GroceryFactory.create(groceryItemName, price, expirationDate);
		GroceryItem second = GroceryFactory.create(groceryItemName, price, expirationDate);
		Assert.assertNotEquals(first.hashCode(), second.hashCode());
	}
}